import java.io.*;

public final class FileUtil {
    private FileUtil() {}
    public static String readFile(File f, String encoding) {
        String ret = null;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), encoding));
            char content[] = new char[1024];
            int len = 0;
            StringBuilder sb = new StringBuilder();
            while ((len = reader.read(content)) != -1) {
                sb.append(new String(content, 0, len));
            }
            ret = sb.toString();
            reader.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return ret;
    }
    public static void saveFile(File f, String content, String encoding) {
        try {
            OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), encoding);
            writer.write(content);
            writer.flush();
            writer.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}